#
# @lc app=leetcode.cn id=844 lang=python3
#
# [844] 比较含退格的字符串
#

# @lc code=start
class Solution:
    def backspaceCompare(self, s: str, t: str) -> bool:
        arr1 = [''] * len(s)
        arr2 = [''] * len(t) 
        idx1 = 0
        for ch in s:
            if ch == '#':
                if idx1 > 0:
                    idx1 -= 1
            else:
                arr1[idx1] = ch
                idx1 += 1
        
        idx2 = 0
        for ch in t:
            if ch == '#':
                if idx2 > 0:
                    idx2 -= 1
            else:
                arr2[idx2] = ch
                idx2 += 1

        if idx1 != idx2:
            return False
        for i in range(idx1):
            if arr1[i] != arr2[i]:
                return False
        return True
# @lc code=end

s = Solution()
print(s.backspaceCompare("y#fo##f", "y#f#o##f"))
